package test.core.structs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.junit.Test;

import com.alibaba.fastjson.JSON;

public class testsort {
	@Test
	public void fun1() {
		List<mm> mlist=new ArrayList<>();
		mlist.add(	new mm(12,"小规"));
		mlist.add(	new mm(18,"小个"));
		mlist.add(	new mm(14,"小给"));
		mlist.add(	new mm(14,"小过"));
		mlist.add(	new mm(16,"小不"));
		Collections.sort(mlist);
		System.out.println(JSON.toJSONString(mlist));
	}
}
class mm  implements Comparable<mm>{
	public mm(int age,String name) {
		this.age = age;
		this.name = name;
	}
    /*属性、getter/setter方法、toString方法及构造方法略*/
    @Override
    public int compareTo(mm emp) {
        /*按员工编号正序排序*/
        return this.age-emp.age;
        /*按员工编号逆序排序*/
        //return emp.getEmpno()-this.getEmpno();
        /*按员工姓名正序排序*/
        //return this.getEname().compareTo(emp.getEname());
        /*按员工姓名逆序排序*/
      //  return emp.l完成块.compareTo(this.getL完成块());
    }
	public int age;
	public String name;
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
}